package com.swz.dcrm.ui.daily;


import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.swz.dcrm.adpter.GlobalAdapter;
import com.swz.dcrm.model.BaseResponse;
import com.swz.dcrm.model.DailyTarget;
import com.swz.dcrm.ui.base.BaseFragment;
import com.swz.dcrm.R;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.navigation.fragment.NavHostFragment;

import android.widget.ProgressBar;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;

import com.swz.dcrm.R;
import com.swz.dcrm.ui.viewmodel.AnalyzeViewModel;

import javax.inject.Inject;

/**
 * A simple {@link Fragment} subclass.
 */
public class DailyTargetFragment extends BaseFragment {


    @BindView(R.id.tv_build_count)
    TextView tvBuildCount;
    @BindView(R.id.tv_order_count)
    TextView tvOrderCount;
    @BindView(R.id.progress_bar1)
    ProgressBar progressBar1;
    @BindView(R.id.progress_bar2)
    ProgressBar progressBar2;

    @BindView(R.id.progress_bar3)
    ProgressBar progressBar3;

    @BindView(R.id.progress_bar4)
    ProgressBar progressBar4;

    @BindView(R.id.progress_bar5)
    ProgressBar progressBar5;

    @BindView(R.id.progress_bar6)
    ProgressBar progressBar6;

    @BindView(R.id.progress_bar7)
    ProgressBar progressBar7;
    @BindView(R.id.tv_count1)
    TextView tvCount1;
    @BindView(R.id.tv_count2)
    TextView tvCount2;
    @BindView(R.id.tv_count3)
    TextView tvCount3;
    @BindView(R.id.tv_count4)
    TextView tvCount4;
    @BindView(R.id.tv_count5)
    TextView tvCount5;
    @BindView(R.id.tv_count6)
    TextView tvCount6;
    @BindView(R.id.tv_count7)
    TextView tvCount7;

    @Inject
    AnalyzeViewModel analyzeViewModel;

    public static DailyTargetFragment newInstance() {

        return new DailyTargetFragment();
        // Required empty public constructor
    }

    @Override
    public void onLoadRetry() {
        if (!isNetworkConnected(getContext())){
            mHolder.showLoadingStatus(GlobalAdapter.NET_ERROR);
            return;
        }
        analyzeViewModel.getDailyTarget().observe(this, new Observer<BaseResponse<DailyTarget>>() {
            @Override
            public void onChanged(BaseResponse<DailyTarget> dailyTargetBaseResponse) {
                if(dailyTargetBaseResponse.isSuccess()){
                    DailyTarget dailyTarget=dailyTargetBaseResponse.getData();
                    tvBuildCount.setText(dailyTarget.getTargetBuildFileCount()+"");
                    tvOrderCount.setText(dailyTarget.getTargetOrderCount()+"");
                    tvCount1.setText(dailyTarget.getNewCreateCustomerCount()+"");
                    tvCount2.setText(dailyTarget.getComeShopCount()+"");
                    tvCount3.setText(dailyTarget.getTestDriveCount()+"");
                    tvCount4.setText(dailyTarget.getOrderCount()+"");
                    tvCount5.setText(dailyTarget.getDeliveryCarCount()+"");
                    tvCount6.setText(dailyTarget.getDefeatedCount()+"");
                    tvCount7.setText(dailyTarget.getCancelOrderCount()+"");
                }
            }
        });

    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        onLoadRetry();
    }

    @Override
    public int layoutId() {
        return R.layout.fragment_daily_target;
    }

    @Override
    public boolean initView() {
        getDigger().inject(this);
        return false;
    }
    @OnClick({R.id.ll_type1,R.id.ll_type2,R.id.ll_type3,R.id.ll_type4,R.id.ll_type5,R.id.ll_type6,R.id.ll_type7})
    public void click(View view){
        DailyTargetDetailFragmentArgs.Builder builder=new DailyTargetDetailFragmentArgs.Builder();
        builder.setType("daily");
        switch (view.getId()){
            case R.id.ll_type1:
                builder.setTitle(getString(R.string.daily_target_tag1));
                break;
            case R.id.ll_type2:
                builder.setTitle(getString(R.string.daily_target_tag2));
                break;
            case R.id.ll_type3:
                builder.setTitle(getString(R.string.daily_target_tag3));
                break;
            case R.id.ll_type4:
                builder.setTitle(getString(R.string.daily_target_tag4));
                break;
            case R.id.ll_type5:
                builder.setTitle(getString(R.string.daily_target_tag5));
                break;
            case R.id.ll_type6:
                builder.setTitle(getString(R.string.daily_target_tag6));
                break;
            case R.id.ll_type7:
                builder.setTitle(getString(R.string.daily_target_tag7));
                break;
        }
        go(null,R.id.action_dailyFragment_to_dailyTargetDetailFragment,builder.build().toBundle());
    }


}
